package vn.orderonline.com.core.business.toorder;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import vn.orderonline.com.core.business.dto.FoodBasketDto;
import vn.orderonline.core.dao.entity.FoodBasket;
import vn.orderonline.core.dao.toorder.FoodBasketDao;

@Service
@Transactional
public class FoodBasketImpl implements IFoodBasket {
	
	@Autowired
	private FoodBasketDao foodBasketDao;

	@Override
	public List<FoodBasketDto> getAllByOrderId(Integer orderId) {
		List<FoodBasket> list = foodBasketDao.findByProp("id.orderId", orderId);
		List<FoodBasketDto> listDto = null;
		if (!list.isEmpty()) {
			listDto = new ArrayList<>();
			FoodBasketDto dto = null;
			for (FoodBasket fb : list) {
				dto = new FoodBasketDto();
				dto.setFoodId(fb.getId().getFoodId());
				dto.setOrderId(fb.getId().getOrderId());
				dto.setFoodName(fb.getFoodName());
				dto.setAmount(fb.getAmount());
				dto.setPrice(fb.getPrice());
				listDto.add(dto);
			}
		}
		return listDto;
	}

}
